package com.gitee.wsl.ext.map

import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

@OptIn(ExperimentalContracts::class)
fun Map<*, *>?.isNullOrEmpty(): Boolean {
    contract {
        returns(false) implies (this@isNullOrEmpty != null)
    }

    return this == null || isEmpty()
}

@OptIn(ExperimentalContracts::class)
fun Map<*, *>?.isNotNullOrEmpty(): Boolean {
    contract {
        returns(true) implies (this@isNotNullOrEmpty != null)
    }

    return this != null && isNotEmpty()
}


fun <K, V> Map<K, V>.containsAll(other: Map<K, V>): Boolean {
    if (this === other)
        return true
    if (this.size < other.size)
        return false

    for ((key, otherValue) in other) {
        if (key !in this || this[key] != otherValue)
            return false
    }

    return true
}